package com.thinkgem.jeesite.modules.fantasy.service.impl;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.fantasy.bean.ItemBean;
import com.thinkgem.jeesite.modules.fantasy.dao.CabinetDao;
import com.thinkgem.jeesite.modules.fantasy.dao.ItemDao;
import com.thinkgem.jeesite.modules.fantasy.entity.Cabinet;
import com.thinkgem.jeesite.modules.fantasy.entity.Item;
import com.thinkgem.jeesite.modules.fantasy.utils.ItemFactory;
import com.thinkgem.jeesite.modules.fantasy.utils.PageParameter;
@Service
public class ItemService extends CrudService<ItemDao, Item> {
	@Autowired
	ItemDao itemDao;
	@Autowired
	CabinetDao cabinetDao;

	public List<Item> getPocketItems(String userid) {
		List<Item> pocketItems = itemDao.getPocketItems(userid);
		return pocketItems;
	}
	
	public int pickItem(Item item) {
		return itemDao.pickItem(item);
	}

	public Item getItemById(String itemid) {
		
		return itemDao.getItemById(itemid);
	}

	public String useItem(Item item, String whereami) {
		String message = "";
		System.out.println("Ownerid == " + item.getOwnerid());
		ItemBean itemBean;
		String beanName = item.getBeanname();
		System.out.println("beanName = " + beanName);
		if (beanName != null) {
			itemBean = ItemFactory.getItemBean(beanName+"Bean");
		} else {
			itemBean = ItemFactory.getItemBean("otherItemBean");
		}
		itemBean.setUsePosition(whereami);
		message = itemBean.useItem(item);
		/*if ("柜子".equals(item.getName())) {
			if ("home".equals(whereami)) {
				//ItemBean itemBean = new CabinetBean();
				//itemBean.setUseBehavior("install");
				ItemBean itemBean = ItemFactory.getItemBean("cabinetBean");
				
				itemBean.useItem(item);
				//cabinetDao.addCabinet(item.getOwnerid());
			} else {
				System.out.println("柜子只能在家中使用。");
				message = "柜子只能在家中使用。";
			}
		} else {
			ItemBean itemBean = ItemFactory.getItemBean("otherItemBean");
			//ItemBean itemBean = new OtherItemBean();
			itemBean.useItem(item);
		}*/
		return message;
	}
	
	public List<Cabinet> getCabinetsByUserid(String userid) {
		return cabinetDao.getCabinetsByUserid(userid);
	}
	
	public int movingCabinet(Map<?, ?> map) {
		return itemDao.movingCabinet(map);
	}
	
	public List<Item> getItemsByCabinetId(Map<?, ?> map) {
		return itemDao.getItemsByCabinetId(map);
	}
	
	public Cabinet getCabinetById(String cabinetid) {
		return cabinetDao.getCabinetById(cabinetid);
	}
	
	public int countItemNumber(Map<?, ?> map) {
		return itemDao.countItemNumber(map);
	}
	
	public int editCabinetName(Map<?, ?> map) {
		return cabinetDao.editCabinetName(map);
	}
	
	public int removeItemById(String itemid) {
		return itemDao.removeItemById(itemid);
	}
	public int dropItem(Item item) {
		
		return -1;
	}
	public List<Item> getItemsByUserId(Map<?, ?> map) {
		return itemDao.getItemsByUserId(map);
	}

	public int queryItemsCountByUserId(PageParameter pageParameter) {
		return itemDao.queryItemsCountByUserId(pageParameter);
	}

	public List<Item> selectPageItems(PageParameter pageParameter) {
		return itemDao.selectPageItems(pageParameter);
	}
	
}
